#ifndef _BSP_NOR_QPI__H_
#define _BSP_NOR_QPI__H_

#include "stdint.h"

/*****************************************************************************
* @brief   SIGNAL NOR-FLASH API
*****************************************************************************/
uint32_t bsp_snor_init(uint8_t qspi_en);

// 寄存器操作 1 2 3
uint8_t bsp_snor_reg_get(char reg);
uint8_t bsp_snor_reg_set(char reg, uint8_t msk, uint8_t val);

// 状态
uint32_t bsp_snor_st_read(void);	  // st read = reg1 + reg2 + reg3
uint8_t bsp_snor_busy(void);		  // get busy st, reg1.b0
uint8_t bsp_snor_wait_for_busy(void); // return 1 is ok, 0 is error.

// ID
uint8_t bsp_snor_id_read(uint8_t *des);

// 写使能
void bsp_snor_write_enable(void);
void bsp_snor_write_disable(void);

// 擦除
uint8_t bsp_snor_sector_erase(uint32_t addr);
uint8_t bsp_snor_block_erase(uint32_t addr);
uint8_t bsp_snor_block64_erase(uint32_t addr);
uint8_t bsp_snor_chip_erase(void);

// SPI 读写
uint8_t bsp_snor_read(uint32_t addr, int32_t Len, uint8_t *Des);
uint8_t bsp_snor_write(uint32_t addr, int32_t Len, const uint8_t *Src);
uint8_t bsp_snor_write_multi(uint32_t addr, int32_t Len, const uint8_t *Src); // 内部分页

// 附加安全区
uint8_t bsp_snor_security_reg_read(uint32_t addr, int32_t Len, uint8_t *Des);
uint8_t bsp_snor_security_reg_write(uint32_t addr, int32_t Len, const uint8_t *Src);
uint8_t bsp_snor_security_reg_erase(uint32_t addr);

// 单字节命令
void bsp_snor_cmd_exe(uint8_t cmd);
void bsp_snor_cmd_set(uint8_t cmd, uint8_t par);
uint8_t bsp_snor_cmd_get(uint8_t cmd);
void bsp_snor_cmd_auto_set(uint8_t cmd, const uint8_t *buff, uint8_t cnt);
void bsp_snor_cmd_auto_get(uint8_t cmd, uint8_t *buff, uint8_t cnt);

// A32 基本命令
uint8_t bsp_snor32_enter_a32_mode(void);
uint8_t bsp_snor32_enter_a24_mode(void);
uint8_t bsp_snor32_addr_mb_set(uint8_t mb);
uint8_t bsp_snor32_addr_mb_get(void);

uint8_t bsp_snor32_sector_erase(uint32_t addr);
uint8_t bsp_snor32_block_erase(uint32_t addr);
uint8_t bsp_snor32_block64_erase(uint32_t addr);

// A32 SPI 读写
uint8_t bsp_snor32_read(uint32_t addr, int32_t Len, uint8_t *Des); 
uint8_t bsp_snor32_write(uint32_t addr, int32_t Len, const uint8_t *Src);
uint8_t bsp_snor32_write_multi(uint32_t addr, int32_t Len, const uint8_t *Src);

#endif /* _BSP_NOR_QPI__H_ */
